package com.sugon.controller.module;

import com.sugon.annotation.AutoLog;
import com.sugon.entity.ModuleErrorEntity;
import com.sugon.service.ModuleErrorService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 模具异常记录Controller
 *
 * @author sugon
 * @date 2019-08-02 11:49:37
 */
@Controller
@RequestMapping("moduleerror")
public class ModuleErrorController {
    @Autowired
    private ModuleErrorService moduleErrorService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("moduleerror:list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<ModuleErrorEntity> moduleErrorList = moduleErrorService.queryList(query);
        int total = moduleErrorService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(moduleErrorList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("moduleerror:info")
    @ResponseBody
    public R info(@PathVariable("id") String id) {
        ModuleErrorEntity moduleError = moduleErrorService.queryObject(id);

        return R.ok().put("moduleError", moduleError);
    }

    /**
     * 保存
     */
    @AutoLog("模具维护异常记录新增")
    @RequestMapping("/save")
    @RequiresPermissions("moduleerror:save")
    @ResponseBody
    public R save(@RequestBody ModuleErrorEntity moduleError) {
        moduleErrorService.save(moduleError);

        return R.ok();
    }

    /**
     * 修改
     */
    @AutoLog("模具维护异常记录修改")
    @RequestMapping("/update")
    @RequiresPermissions("moduleerror:update")
    @ResponseBody
    public R update(@RequestBody ModuleErrorEntity moduleError) {
        moduleErrorService.update(moduleError);

        return R.ok();
    }

    /**
     * 删除
     */
    @AutoLog("模具维护异常记录删除")
    @RequestMapping("/delete")
    @RequiresPermissions("moduleerror:delete")
    @ResponseBody
    public R delete(@RequestBody String[] ids) {
        moduleErrorService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<ModuleErrorEntity> list = moduleErrorService.queryList(params);

        return R.ok().put("list", list);
    }

    /**
     * 审核
     */
    @RequestMapping("/review")
    @RequiresPermissions("moduledata:review")
    @ResponseBody
    public R review(@RequestBody ModuleErrorEntity moduleError) {
        moduleErrorService.review(moduleError);

        return R.ok();
    }
    /**
     * 查看信息
     */
    @RequestMapping("/getInfoByMaintainRecord/{maintainRecord}")
    @ResponseBody
    public R getInfoByMaintainRecord(@PathVariable("maintainRecord") String maintainRecord) {
        ModuleErrorEntity moduleError = moduleErrorService.getInfoByMaintainRecord(maintainRecord);

        return R.ok().put("moduleError", moduleError);
    }
    @AutoLog("模具维护异常记录处理")
    @RequestMapping("/updateOption")
    @ResponseBody
    public R updateOption(@RequestBody ModuleErrorEntity moduleError) {
        moduleErrorService.update(moduleError);

        return R.ok();
    }


}
